﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KeywordAuction;

namespace Simulation.Mechanism
{
    public class VCGAuctionMechanism : IAuctionMechanism
    {
        public double GetPaymentValue(int adspotIndex, List<double> clickThroughtRates, List<AdvertiserBidding> bitters)
        {
            var bidsAdspot = bitters.OrderByDescending(p => p.Bid).ToList();
            double result = 0;
            for (int i = adspotIndex; i < bidsAdspot.Count - 1; i++)
            {
                double rate = clickThroughtRates[i];
                double rateNext = clickThroughtRates[i + 1];

                result += (rate - rateNext) * bidsAdspot[i+1].Bid;
            }
            return result;
        }
    }


}
